#include "../Basics/BasicStruct.cpp"

// 创建哈希表

#define p 10
#define NULLKEY -1

int HashKey(int key) {
    return key % p;
}

void CreateHashTable(HashTable ht,int n) {
    //key赋初值
    for (int i = 0; i < p; ++i) {
        ht->key[i] = NULLKEY;
    }
    for (int i = 0; i < n; ++i) {
        // 输入需要加入哈希表的元素
        int data;
        scanf("%d",&data);
        // hash算法获取在哈希表中的位置.
        int pos = HashKey(data);
        if (ht->key[pos] == NULLKEY) {
            ht->key[pos] = data;
        } else{
            // 有冲突则二次哈希.
            for (int j = 1; j < p; ++j) {
                int newKey = HashKey(data+j);
                if (ht->key[newKey] == NULLKEY) {
                    ht->key[newKey] = data;
                    break;
                }
            }
        }
    }
}

int main() {
    HashTable ht = (HashTable) malloc(sizeof(H));
    CreateHashTable(ht,6);
}
